﻿using MediatR;
using ProduceBasicData.Api.Application.Command.ProductionManage.Plan;
using ProduceBasicData.Api.DTO.ProductionManage;
using ProduceBasicData.Domain.ProductionManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.ProductionManage.Plan
{
    public class GetPlan_SchedulingCommandHandler : IRequestHandler<GetPlan_SchedulingCommand, ApiResult<List<Plandto>>>
    {
        private readonly IBaseRespository<Plan_Scheduling> planrepositry;

        public GetPlan_SchedulingCommandHandler(IBaseRespository<Plan_Scheduling> planrepositry)
        {
            this.planrepositry = planrepositry;
        }

        public Task<ApiResult<List<Plandto>>> Handle(GetPlan_SchedulingCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<List<Plandto>>()
            {
                Code=ApiEnum.Success,
                Msg="获取排班信息成功"
            };  

            var info=from a in planrepositry.GetAll()
                     where a.UserId == request.UserId && !a.Isdel
                    select new Plandto()
            {
                UserId=a.UserId,
                Id=a.Id,
                Type=a.Type,
                Notes=a.Notes,
                Date=a.Date.ToString("yyyy-MM-dd"),
            };

            result.Data = info.ToList();

            return  Task.FromResult(result);
        }
    }
}
